package org.elephas.webapp.frontend.page.blog;

import org.apache.wicket.Component;
import org.apache.wicket.PageParameters;
import org.elephas.model.Blog;
import org.elephas.webapp.frontend.resource.BlogFeedResourceReference;
import org.elephas.webapp.frontend.resource.FeedResource;

/**
 * Renders the recent posts of a blog.
 *
 * @author Gerolf Seitz
 */
public class BlogFrontPage extends BlogBasePage {
    private static final long serialVersionUID = 1L;

    public BlogFrontPage(PageParameters params) {
        super(params);
        add(FeedResource.autodiscoveryLink(new BlogFeedResourceReference(getBlogModel())));
    }

    @Override
    protected Component newContent(String id) {
        return getTheme().newFrontPageContent(id, getBlogModel(), this);
    }

    /**
     * Creates a {@link PageParameters} object based on the given {@link Blog} object.
     *
     * @param blog the blog
     *
     * @return the page parameter for the {@link BlogFrontPage}
     */
    public static PageParameters constructPageParameters(Blog blog) {
        PageParameters params = new PageParameters();
        if(blog != null) {
            params.add(BLOG_NAME, blog.getName());
        }
        return params;
	}
}